<?php
$json_string = file_get_contents('install_sql.json');
$dataxxx = json_decode($json_string, true);
header ( "Content-type:text/html;charset=utf-8" );
$link=mysqli_connect($dataxxx[1],$dataxxx[2],$dataxxx[3]);//链接数据库
if($link)
  { 
    //echo"链接数据库成功";
    $select=mysqli_select_db($link,$dataxxx[4]);//选择数据库
    if($select)
    {
      //echo"选择数据库成功！";
      if(isset($_POST["sub"]))
      {
        $name=$_POST["username"];
        $password1=$_POST["password"];//获取表单数据
       $password2=$_POST["password2"];
        if($name==""||$password1=="")//判断是否填写
        {
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."请填写完整"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."../logon.php"."\""."</script>";
          exit;
        }
        if($password1==$password2)//确认密码是否正确
       {
        $str="select count(*) from `OurShareUserName` where username="."'"."$name"."'";
        $result=mysqli_query($link,$str);
        $pass=mysqli_fetch_row($result);
       $pa=$pass[0];
        if($pa==1)//判断数据库表中是否已存在该用户名
        {
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."该用户名已被注册"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."../logon.php"."\""."</script>";
        exit;
        }
$vip="1";
        $sql="insert into `OurShareUserName` values("."\""."$name"."\"".","."\""."$password1"."\"".","."\""."$vip"."\"".")";//将注册信息插入数据库表中
        //echo"$sql";
        mysqli_query($link,$sql);
        mysqli_query('SET NAMES UTF8');
        $close=mysqli_close($link);
        if($close)
        {
          //echo"数据库关闭";
          //echo"注册成功！";
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."ok！"."\"".")".";"."</script>"; 
echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."../return.php"."\""."</script>";
        }
        }
        else{
echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."两次不一致！"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."../logon.php"."\""."</script>";
        }
      }
    }
  }
?>